<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>添加新手手册</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

		<link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
		<link rel="stylesheet" href="/css/global.css" media="all">
		<link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="/css/table.css"/>

		<style>
			.layui-form-label {
				width: 10%;
			}
			.layui-input-block {
				margin-left: 12%;
			}
			.required-field {
				color: red;
				margin-right: 2px;
				font-size: 15px;
				text-align: center;
			}

		</style>
	</head>
	<body>
		<div style="margin: 15px;">
			<!--<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
				<legend>新手手册一级标题编辑</legend>
			</fieldset>-->

			<form class="layui-form" id="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label layui-required-tip">原密码：</label>
					<div class="layui-input-block">
						<input type="password" name="password" lay-verify="required|password" placeholder="请输入原密码" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label layui-required-tip">新密码：</label>
					<div class="layui-input-block">
						<input type="password" id="NEWPWD" name="newpwd" lay-verify="required|newpwd" placeholder="请输入新密码，长度6-20位" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label layui-required-tip">确认新密码：</label>
					<div class="layui-input-block">
						<input type="password" name="renewpwd" lay-verify="required|renewpwd" placeholder="请再输入新密码已做确认" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary" >重置</button>
					</div>
				</div>
			</form>
		</div>
		<script type="text/javascript" src="/plugins/layui/layui.js"></script>
		<script type="text/javascript" src="/js/global-config.js"></script>
		<script>
            layui.use(['form', 'layedit', 'laydate'], function() {
                var form = layui.form;
                var $ = layui.jquery;
                var layer = layui.layer; //获取当前窗口的layer对象
                form.verify({
                    newpwd: [
                        /^[\S]{6,20}$/
                        ,'密码长度限填6-20位'
                    ]
                    ,renewpwd: function(value) {
                        if(value != NEWPWD.value){
                            return '两次输入的密码不一致!';
                        }
					}
                });
                form.render();

                layer.ready(function () {
                    var $layer = $('#layui-form');

                    //监听提交监听提交
                    form.on('submit(demo1)', function(data){
                        var flag = true;
                        if (flag) {
                            layer.confirm('确认要提交吗？', {
                                btn : [ '确定', '取消' ]//按钮
                            }, function(index) {
                                $.ajax({
                                    type : "POST",
                                    url : "/modifyPWD",
                                    dataType : "json",
                                    data :data.field,
                                    success : function(data) {
                                        console.log(data);
                                        if(data.data=="1") {
                                            alert("修改成功！");
                                            window.top.location = "/login";
										} else {
                                            alert("原密码错误！");
										}
                                    },
                                    error : function() {
                                        alert("系统异常,请稍后重试");
                                    }
                                });
                                layer.close(index);
                            });
                        }
                        return false;
                    });

                })
            });
		</script>
	</body>
</html>